import config from '@/config.js'
import {getStorage} from '@/util/auth.js';
export function uploadFile(filePath,auth=false){
	return new Promise((resolve,reject)=>{
		var para={
			url:config.requestUrl+'/api/upload',
			filePath,
			header: { "Content-Type": "multipart/form-data" },
			name:'file',
			success:(res)=>{
				resolve(res)
			},
			fail(res) {
				reject(res)
			}
		}
		if(auth){
			const token=getStorage('login');
			if(token){
				para.header['token']=token.token;
			}
		}
		uni.uploadFile(para)
	})
}
export function downloadFile(url){
	return new Promise((resolve,reject)=>{
		uni.downloadFile({
			url,
			success:(res)=>{
				resolve(res)
			},
			fail(res) {
				reject(res)
			}
		})
	})
}